package engine.systems.update
{
	import ash.core.Node;
	import ash.tools.ListIteratingSystem;
	
	import engine.utils.EntityUtils;
	
	/**
	 * Game System extends List Iterating System, but with one addition. Game System checks for
	 * entities that are sleeping. Entities could be sleeping if they have a Sleep component,
	 * Group, or Parent that's currently sleeping.
	 * 
	 * <p>If the entity isn't sleeping, it can be updating in whatever system it's being updated in that
	 * extends Game System.
	 * 
	 * @see Sleep
	 * @see SleepNode
	 * @see SleepSystem
	 */
	public class GameSystem extends ListIteratingSystem
	{
		public function GameSystem(nodeClass:Class, nodeUpdateFunction:Function, nodeAddedFunction:Function = null, nodeRemovedFunction:Function = null)
		{
			super(nodeClass, nodeUpdateFunction, nodeAddedFunction, nodeRemovedFunction);
		}
		
		override public function update(time:Number):void
		{
			for(var node:Node = this.nodeList.head; node; node = node.next)
			{
				if(EntityUtils.sleeping(node.entity)) continue;
				
				this.nodeUpdateFunction(node, time);
			}
		}
	}
}